//
//  NewsCell.m
//  WY
//
//  Created by lanou3g on 16/5/10.
//  Copyright © 2016年 pcc. All rights reserved.
//

#import "NewsCell.h"
#import "NewsModel.h"
#import "NewsImageModel.h"
#import "UIImageView+WebCache.h"
@interface NewsCell ()
//小图 正常图片
@property (weak, nonatomic) IBOutlet UIImageView *iconView;
//标题
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
//摘要
@property (weak, nonatomic) IBOutlet UILabel *digestLabel;
//回帖数
@property (weak, nonatomic) IBOutlet UILabel *replyCountLabel;
//多图数组
@property (strong, nonatomic) IBOutletCollection(UIImageView) NSArray *imgextra;


@end
@implementation NewsCell


-(void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
}

-(void)setNewsModel:(NewsModel *)newsModel {
    if (_newsModel != newsModel) {
        _newsModel = newsModel;
        
        [self.iconView sd_setImageWithURL:[NSURL URLWithString:_newsModel.imgsrc]];
        self.titleLabel.text = self.newsModel.title;
        self.digestLabel.text = self.newsModel.digest;
        self.replyCountLabel.text = [NSString stringWithFormat:@"%ld跟帖", (long)self.newsModel.replyCount];
        if (_newsModel.imgextra) {
            //set more image
            [self.imgextra enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                NewsImageModel *image = _newsModel.imgextra[idx];
                [obj sd_setImageWithURL:[NSURL URLWithString:image.imgsrc] placeholderImage:[UIImage imageNamed:@"cell_image_background@2x.png"] options:SDWebImageRetryFailed | SDWebImageLowPriority];
            }];
        }
    }
}

+ (NSString *)cellIdentiferWithNews:(NewsModel *)newsModel {
    if (newsModel.imgextra) {
        return @"NewsMoreImageCell";
    }else if (newsModel.imgType == 1){
        return @"NewsBigImageCell";
    }else{
        return @"NewsCell";
    }
}
+ (CGFloat)cellHeightWithNews:(NewsModel *)newsModel {
    if (newsModel.imgextra) {
        return 120;
    }else if (newsModel.imgType == 1) {
        return 150;
    }else {
        return 100;
    }
}

@end
